<meta charset=utf-8>
<style>
body { margin: 0px; }
canvas { width:100%; height:100%; overflow: hidden; }
</style>
<head><meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1">
<script type="text/javascript" src="../h3du_min.js"></script>
<script type="text/javascript" src="../extras/frame.js"></script>
<script type="text/javascript" src="demoutil.js"></script>
<script type="text/javascript" src="../extras/meshjson.js"></script>
</head>
<body>
<canvas id=canvas></canvas>
<p>Texture courtesy of pdtextures.blogspot.com</p>
<script id="demo">
/* global H3DU */
// <!--
/*
 Any copyright to this file is released to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/
 If you like this, you should donate
 to Peter O. (original author of
 the Public Domain HTML 3D Library) at:
 http://peteroupc.github.io/
*/

  // Create the 3D scene; find the HTML canvas and pass it
  // to Scene3D.
  var scene = new H3DU.Scene3D(document.getElementById("canvas"))
    .cullFace(H3DU.Scene3D.BACK)
    .setClearColor("white")
  var sub = new H3DU.Batch3D()
   // Set the perspective view. Camera has a 45-degree field of view
   // and will see objects from 0.1 to 100 units away.
   .perspectiveAspect(45, 0.1, 100)
   // Move the camera back 40 units.
   .setLookAt([0, 0, 40]);
  sub.getLights().setBasic();
  var fc = new H3DU.FrameCounterDiv();
  var loader = new H3DU.TextureLoader();
  loader.loadAndMapTexturesAll([
    "461223191.jpg",
    "specular.png"
  ], scene).then(function(tex) {
    "use strict";
    var mesh = H3DU.Meshes.createBox(10, 20, 20);
    var shape = new H3DU.Shape(mesh).setMaterial(
      new H3DU.Material({
        "diffuse":"white",
        "specular":"white",
        "shininess":20,
        "texture":tex[0],
        "specularMap":tex[1]
      }));
    sub.addShape(shape);
   // Create a timer
    var timer = {};
  // Set up the render loop
    H3DU.renderLoop(function(time) {
   // Update the shape's rotation
      var q = H3DU.Math.quatFromTaitBryan(
     360 * H3DU.getTimePosition(timer, time, 6000),
     360 * H3DU.getTimePosition(timer, time, 12000),
     0
   );
      fc.update();
      shape.setQuaternion(q);
   // Render the scene
      scene.render(sub);
    });
  });
// -->
</script>
</body>
